(function() {
  var Moshu, tests;

  Moshu = window.Moshu;

  tests = new Moshu.Tests("");

  tests.add("Vector", function() {
    var r, v1, v2;
    v1 = new Moshu.Canvas2D.Vector(15, 33);
    tests.assert("Constructor test - ", v1.x() === 15 && v1.y() === 33);
    v2 = new Moshu.Canvas2D.Vector(75, 12);
    r = v1.substract(v2);
    tests.assert("Substraction test - ", r.x() === -60 && r.y() === 21);
    r = v1.add(v2);
    tests.assert("Addition test - ", r.x() === 90 && r.y() === 45);
    r = v1.dotProduct(v2);
    tests.assert("Dot product test - ", r === 1521);
    r = v1.getPerpendicular();
    tests.assert("Get perpendicular test - ", r.x() === 33 && r.y() === -15);
    r = v1.getMagnitude();
    return tests.assert("Get magnitude test - ", r === 36.24913792078372);
  });

  tests.add("PhysicalObject", function() {
    var o, r, v1;
    o = new Moshu.Canvas2D.PhysicalObject();
    v1 = new Moshu.Canvas2D.Vector(15, 33);
    o.fixed = true;
    o.velocity(v1);
    r = o.velocity();
    tests.assert("Set velocity of fixed obj", r.x() === 0 && r.y() === 0);
    o.fixed = false;
    o.velocity(v1);
    r = o.velocity();
    tests.assert("Set velocity of mobile obj", r.x() === 15 && r.y() === 33);
    o.fixed = false;
    o.velocity(v1);
    o.mass = 2;
    r = o.getMomentum();
    return tests.assert("GetMomentum ", r.x() === 30 && r.y() === 66);
  });

  tests.add("Polygon", function() {
    var axis, o, o1, projection, r, sides, vertices;
    vertices = [new Moshu.Canvas2D.Vector(0, 0), new Moshu.Canvas2D.Vector(0, 100), new Moshu.Canvas2D.Vector(100, 100)];
    o = new Moshu.Canvas2D.Polygon(vertices);
    tests.assert("Constructor test", o._vertices.length === 3 && o._vertices[0].x() === 0 && o._vertices[0].y() === 0 && o._vertices[1].x() === 0 && o._vertices[1].y() === 100 && o._vertices[2].x() === 100 && o._vertices[2].y() === 100);
    o.move(new Moshu.Canvas2D.Vector(100, 100));
    tests.assert("Move test", o._vertices.length === 3 && o._vertices[0].x() === 100 && o._vertices[0].y() === 100 && o._vertices[1].x() === 100 && o._vertices[1].y() === 200 && o._vertices[2].x() === 200 && o._vertices[2].y() === 200);
    o = new Moshu.Canvas2D.Polygon(vertices);
    sides = o.getSidesVectors();
    tests.assert("getSidesVectors", sides[0].x() === 0 && sides[0].y() === -100);
    axis = sides[2];
    axis = axis.getPerpendicular();
    projection = o.getProjection(axis);
    tests.assert("getProjection", projection[0] === -10000 && projection[1] === 0);
    o1 = new Moshu.Canvas2D.Polygon([new Moshu.Canvas2D.Vector(0, 80), new Moshu.Canvas2D.Vector(188, 180)]);
    r = o.getCollision(o1);
    tests.assert("getCollision - colliding", r);
    o1 = new Moshu.Canvas2D.Polygon([new Moshu.Canvas2D.Vector(0, 102), new Moshu.Canvas2D.Vector(190, 190)]);
    r = o.getCollision(o1);
    tests.assert("getCollision - not colliding", !r);
    o1.move(new Moshu.Canvas2D.Vector(5, -10));
    r = o.getCollision(o1);
    tests.assert("getCollision - colliding after move", r);
    o1.move(new Moshu.Canvas2D.Vector(5, 10));
    r = o.getCollision(o1);
    return tests.assert("getCollision - not colliding after move", !r);
  });

  tests.test();

}).call(this);
